package com.bai.edu.controller.front;

import com.bai.edu.entity.Course;
import com.bai.edu.entity.Teacher;
import com.bai.edu.service.CourseService;
import com.bai.edu.service.TeacherService;
import com.bai.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@RestController
@RequestMapping("/eduservice/teacherfront")
@CrossOrigin
public class TeacherFrontController {

    @Autowired
    private TeacherService teacherService;
    @Autowired
    private CourseService courseService;

    //分页查询讲师
    @PostMapping("getteacherfrontlist/{page}/{limit}")
    public R getteacherfrontlist(
            @PathVariable long page,
            @PathVariable long limit
    ) {
        Page<Teacher> teacherPage = new Page<>(page, limit);
        Map<String, Object> teachers =teacherService.getTeacherFrontList(teacherPage);
        return R.ok().data(teachers);
    }

    //讲师详情
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId){
        Teacher teacher = teacherService.getById(teacherId);
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<Course> list = courseService.list(wrapper);

        return R.ok().data("teacher",teacher).data("courseList",list);
    }


}
